package com.htc.android.footprints.view;

import java.io.File;
import java.util.Date;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Region;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.util.AttributeSet;
import android.view.View;

import com.htc.android.footprints.utils.camera.FootprintImageManager;
import com.htc.android.footprints.vo.Footprint;

public class PictureViewSmall extends View
  implements IPictureView
{
  private static final String TAG = "PictureViewNew";
  private static Drawable bgDrawable;
  private Handler bHandler;
  private FootprintImageManager.FastBitmapDrawable cacheBmp;
  private Paint datePaint;
  private java.text.DateFormat df;
  boolean isCached;
  boolean isCaching;
  private int mDefaultPictureSize;
  private Footprint mFootprint;
  private String mFormatedDate;
  private int mPhotoWidth;
  private int mPostcardHeight;
  private int mPostcardWidth;
  private Paint namePaint;
  private int offsetDegree = 0;
  private int offsetpPosition = 0;
  private int paddingLeft;
  private float paddingPhoto;
  private int paddingTop;
  private Paint paint;
  private Paint photoPaint;
  private boolean photoReady;
  private Bitmap photoView;

  public PictureViewSmall(Context paramContext)
  {
    super(paramContext);
    initView();
  }

  public PictureViewSmall(Context paramContext, AttributeSet paramAttributeSet)
  {
    super(paramContext, paramAttributeSet);
    initView();
  }

  private void initView()
  {
    this.namePaint = new Paint(1);
    this.datePaint = new Paint(1);
    this.photoPaint = new Paint(3);
    this.df = android.text.format.DateFormat.getDateFormat(getContext());
    if (bgDrawable == null)
      bgDrawable = getContext().getResources().getDrawable(2130837512);
    this.paint = new Paint();
    this.paint.setFilterBitmap(false);
    this.paint.setAntiAlias(false);
  }

  public Footprint getFootprint()
  {
    return this.mFootprint;
  }

  protected void onDraw(Canvas paramCanvas)
  {
    if ((this.mFootprint == null) || (getVisibility() != 0));
    while (true)
    {
      return;
      if (this.isCached)
      {
        paramCanvas.save();
        paramCanvas.translate(0.5F * (getWidth() - this.cacheBmp.getWidth()), 0.0F);
        paramCanvas.drawBitmap(this.cacheBmp.getBitmap(), 0.0F, 0.0F, this.paint);
        paramCanvas.restore();
        continue;
      }
      if ((this.photoReady) && (this.photoView != null) && (!this.isCaching))
      {
        this.isCaching = true;
        if (this.cacheBmp == null)
          this.cacheBmp = new FootprintImageManager.FastBitmapDrawable(Bitmap.createBitmap((int)(1.45D * this.mPostcardWidth), 30 + this.mPostcardHeight, Bitmap.Config.ARGB_8888));
        Canvas localCanvas = new Canvas(this.cacheBmp.getBitmap());
        localCanvas.save();
        localCanvas.translate(0.5F * (this.cacheBmp.getWidth() - getWidth()), 20 + -this.paddingTop);
        draw(localCanvas);
        localCanvas.restore();
        this.isCaching = false;
        this.isCached = true;
        paramCanvas.save();
        paramCanvas.translate(0.5F * (getWidth() - this.cacheBmp.getWidth()), 0.0F);
        this.cacheBmp.draw(paramCanvas);
        paramCanvas.restore();
        continue;
      }
      paramCanvas.save();
      paramCanvas.translate(this.paddingLeft, this.paddingTop);
      if (this.offsetDegree != 0)
        paramCanvas.rotate(this.offsetDegree, this.mPostcardWidth / 2, this.mPostcardHeight / 2);
      if (this.offsetpPosition != 0)
        paramCanvas.translate(this.offsetpPosition, 0.0F);
      paramCanvas.save();
      paramCanvas.clipRect(0, 0, this.mPostcardWidth, this.mPostcardHeight);
      paramCanvas.clipRect(4.0F + this.paddingPhoto, 4.0F + this.paddingPhoto, this.mPhotoWidth + this.paddingPhoto - 4.0F, this.mPhotoWidth + this.paddingPhoto - 4.0F, Region.Op.DIFFERENCE);
      bgDrawable.draw(paramCanvas);
      paramCanvas.restore();
      if ((this.photoReady) && (this.photoView != null))
      {
        paramCanvas.save();
        paramCanvas.translate(this.paddingPhoto, this.paddingPhoto);
        paramCanvas.drawBitmap(this.photoView, 0.0F, 0.0F, this.photoPaint);
        paramCanvas.restore();
      }
      paramCanvas.save();
      paramCanvas.translate(this.paddingPhoto, this.paddingPhoto + this.mPhotoWidth);
      if (this.mFootprint.mName != null)
        paramCanvas.drawText(this.mFootprint.mName, 0, Math.min(this.mFootprint.mName.length(), 20), 0.0F, this.namePaint.getTextSize(), this.namePaint);
      if (this.mFormatedDate != null)
        paramCanvas.drawText(this.mFormatedDate, 0.0F, 3.0F + (this.namePaint.getTextSize() + this.datePaint.getTextSize()), this.datePaint);
      paramCanvas.restore();
      paramCanvas.restore();
    }
  }

  protected void onLayout(boolean paramBoolean, int paramInt1, int paramInt2, int paramInt3, int paramInt4)
  {
    if ((paramBoolean) && ((this.mPostcardWidth == 0) || (this.mPostcardHeight == 0)))
    {
      this.mPostcardHeight = (int)(0.85D * (paramInt4 - paramInt2));
      this.mPostcardWidth = (int)(0.8484848484848485D * this.mPostcardHeight);
      this.namePaint.setTextSize(1.0F + 20.0F * (this.mPostcardWidth / 280.0F));
      this.datePaint.setTextSize(1.0F + 16.0F * (this.mPostcardWidth / 280.0F));
      this.mPhotoWidth = (int)(0.86D * this.mPostcardWidth);
      bgDrawable.setBounds(0, 0, this.mPostcardWidth, this.mPostcardHeight);
      this.paddingPhoto = (0.5F * (this.mPostcardWidth - this.mPhotoWidth) - 1.0F);
      this.paddingTop = ((getHeight() - this.mPostcardHeight) / 2);
      this.paddingLeft = ((getWidth() - this.mPostcardWidth) / 2);
    }
  }

  protected void onMeasure(int paramInt1, int paramInt2)
  {
    int i = View.MeasureSpec.getMode(paramInt1);
    int j = View.MeasureSpec.getMode(paramInt2);
    int k = View.MeasureSpec.getSize(paramInt1);
    int m = View.MeasureSpec.getSize(paramInt2);
    int n;
    if (j == 1073741824)
    {
      n = m;
      if (i != 1073741824)
        break label68;
    }
    label68: for (int i1 = k; ; i1 = (int)(0.8484848484848485D * n))
    {
      setMeasuredDimension(i1, n);
      return;
      n = (int)(0.8D * m);
      break;
    }
  }

  public void reset()
  {
  }

  public void setDefaultPictureSize(int paramInt)
  {
    this.mDefaultPictureSize = paramInt;
  }

  public void setFootprint(Footprint paramFootprint, int paramInt1, int paramInt2)
  {
    if (this.cacheBmp != null)
    {
      this.cacheBmp.getBitmap().eraseColor(0);
      this.isCached = false;
    }
    this.offsetDegree = paramInt1;
    this.offsetpPosition = Math.max(-16, Math.min(16, paramInt2));
    this.mFootprint = paramFootprint;
    this.mFormatedDate = this.df.format(new Date(paramFootprint.mCreateTime));
    this.photoReady = false;
    Footprint localFootprint = this.mFootprint;
    if (this.mFootprint.mPicPath == null);
    for (String str = ""; ; str = this.mFootprint.mPicPath)
    {
      localFootprint.mPicPath = str;
      this.photoView = FootprintImageManager.getInstance().getScaledImage(this.photoView, new File(this.mFootprint.mPicPath), getContext(), this.mDefaultPictureSize, this.mDefaultPictureSize, 3, true);
      this.photoReady = true;
      return;
    }
  }

  public void setHandler(Handler paramHandler)
  {
    this.bHandler = paramHandler;
  }
}

/* Location:           E:\workspace\dex2java\dex-translator-0.0.9.3\HtcFootprints_dex2jar.jar
 * Qualified Name:     com.htc.android.footprints.view.PictureViewSmall
 * JD-Core Version:    0.6.0
 */